package com.mystudy.leetcode.problem.link.p_83;

import com.mystudy.leetcode.base.ListNode;
import com.mystudy.leetcode.base.ListNodeUtils;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 周志龙
 * @Email 15216876513@163.com
 * @Date on 2019/7/4 23:21
 * @Description 删除排序链表中的重复元素
 */
public class Solution {

    @Test
    public void testDelete() {
        ListNode listNode = ListNodeUtils.generateLinkList(new int[]{1, 1, 2, 3, 3});
        ListNode listNode1 = deleteDuplicates(listNode);
        System.out.println(listNode1.val);
    }


    public ListNode deleteDuplicates(ListNode head) {
        ListNode cur = head;
        while (cur != null && cur.next != null) {
            if (cur.val == cur.next.val) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }
        return head;
    }
}
